package com.sam;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class RegServlet
 */
public class RegServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	MemberDAO dao;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegServlet() {
        super();
        dao = new MemberDAO();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userid;
		String username;
		String nickname;
		String password;
		String email;
		String status=" ";
				
		userid = request.getParameter("userid");
		username = request.getParameter("username");
		nickname = request.getParameter("nickname");
		password = request.getParameter("password");
		email = request.getParameter("email");
				
		Member m = new Member(userid, username, nickname, password, email, status);
		HttpSession session = request.getSession();
		session.setAttribute("m", m);
						
		if (m.checkField())  {
			// 註冊成功 Forword
			m.login();
			System.out.println("m.login() = " + m.login());
			response.sendRedirect("index.jsp");
		}else{
			// 註冊失敗
			response.sendRedirect("regest.jsp");
		}
	}

}
